<template>
  <div class="feedback">
    <div class="content">
      <div class="problem1" v-show="addressShow == true">
        <div class="title">退货地址：</div>
        {{ RefundAddress }}
      </div>
      <div class="problem">
        <div class="title">问题描述：</div>
        <van-field
          v-model="message"
          rows="2"
          autosize
          type="textarea"
          maxlength="300"
          placeholder="请描述你遇到的问题或者任何意见或者建议…"
          show-word-limit
        />
      </div>
      <div class="courierNum flexBetween" v-show="addressShow == true">
        <div class="title">快递物流单号:</div>
        <div class="courierNum_body">
          <input type="text" v-model="LogisticsOrderNo" />
        </div>
      </div>
      <div class="up">
        <van-uploader
          v-model="fileList"
          :before-read="beforeRead"
          :after-read="afterRead"
          @delete="handleDelete"
          :max-count="3"
        >
          <template #preview-cover="{ file }">
            <div class="preview-cover van-ellipsis"></div>
          </template>
        </van-uploader>
      </div>
      <div class="tips">只能上传PNG/JPG文件(3张以内)</div>
    </div>
    <div class="tel">
      客服电话：<span
        ><a
          style="text-decoration: none; color: gray; font-weight: 600"
          href="tel:400-820-0668"
          >400-820-0668</a
        ></span
      >
    </div>
    <div class="footer">
      <div class="footer-c">
        <div class="cancel" @click="handleCancel">取消</div>
        <div class="submit" @click="handleSubmit">提交</div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'

export default {
  name: 'feedback',
  data() {
    return {
      number: '1',
      activeIcon: 'https://cdn.92jiangbei.com/bc-double-twelve/circle.png',
      inactiveIcon: 'https://cdn.92jiangbei.com/bc-double-twelve/circle1.png',
      // 问题描述
      message: '',
      // 物流单号
      text: '',
      // 上传照片
      fileList: [],
      imageUrlList: [],
      orderNo: '',
      addressShow: true,
      RefundAddress: '',//退货地址
      LogisticsOrderNo: ''


    }
  },
  created() {
    if (this.$route.query.orderType == 5 || this.$route.query.orderType == 7) {
      this.addressShow = false
    }
    this.orderNo = this.$route.query.orderNo
    this.number = this.$route.query.number
    this.getRefundAdd()
  },
  mounted() {

  },
  methods: {
    handleCancel() {
      this.$router.go(-1)
    },
    handleDelete(file) {
      console.log(file, '1')
    },
    beforeRead(file) {
      // const length = file.size / 1024 < 0.5 * 1024
      // if (!length) {
      //   this.$toast('图片大小不能超过 500kb')
      // }
      let isSuffix = false
      if (file.type === 'image/jpg' || file.type === 'image/png' || file.type === 'image/jpeg') {
        isSuffix = true
      } else {
        this.$toast('请上传png/jpg格式图片')
        isSuffix = false
      }
      return isSuffix
    },
    afterRead(file) {
      file.status = 'uploading'
      file.message = '上传中...'
      const params = new FormData()
      params.append('img', file.file)
      this.$HttpPostImg(this.$api.uploadOss, params).then((res) => {
        if (res.code === '000') {
          file.status = 'success'
          file.message = '上传成功'
          file.iconUrl = res.content[0]
          // this.imageUrlList.push(res.data.content[0])
        } else {
          file.status = 'failed'
          file.message = '上传失败'
        }
      })
    },
    getRefundAdd() { //获取退货地址
      const params = { orderNo: this.$route.query.orderNo };
      console.log('params :>> ', params);
      this.$HttpPost(this.$api.refundAdd, params).then((res) => { // refundAdd  退货地址
        if (res.code === "000") {
          console.log(' 退货地址 ', res.content)
          this.RefundAddress = res.content.refundAddress
        } else {
          console.log(res.desc)
        }
      });
    },
    handleSubmit() { //提交


      if (!this.message || this.message.replace(/\s+/g, '') == '') {
        return Toast('请填写问题描述')
      }

      const params = {
        orderNo: this.$route.query.orderNo,  //类型：String  必有字段  备注：订单号
        remark: this.message, // 类型：String  必有字段  备注：退款信息
        RefundAddress: this.RefundAddress, //地址
        logisticsOrderNumber: this.LogisticsOrderNo,  //类型：String  可有字段  备注：物流单号
        imageUrlOne: this.fileList.length > 0 ? this.fileList[0].iconUrl : '', // 类型：String  可有字段  备注：图片1
        imageUrlTwo: this.fileList.length > 1 ? this.fileList[1].iconUrl : '', // 类型：String  可有字段  备注：图片2
        imageUrlThree: this.fileList.length > 2 ? this.fileList[2].iconUrl : '' // 类型：String  可有字段  备注：图片2
      }
      console.log(params, '退款===》》》this.orderType', this.orderType)
      this.$HttpPost(this.$api.cardQuan, params).then((res) => {
        if (res.code === "000") {
          console.log('订单类型 orderType 5 6 1 7 退款 res', res)
          this.$toast('提交成功', 'middle')
          setTimeout(() => {
            this.$router.go(-1)
          }, 2000)
        } else {
          console.log(res.desc)
        }

      })

    }

  }
}
</script>

<style scoped lang="scss">
.feedback {
  width: 100%;
  // min-height: 100%;
  min-height: 100%;
  background-color: #f4f5f7;
  box-sizing: border-box;
  padding: 0 13px;
  overflow: scroll;

  .img-icon {
    width: 34px;
    height: 34px;
  }

  .content {
    width: 100%;
    min-height: 1000px;
    padding-bottom: 30px;
    background-color: #ffffff;
    border-radius: 22px;

    .style {
      width: 100%;
      height: 104px;
      box-sizing: border-box;
      padding: 0 40px;
      border-bottom: 1px solid #eeeeee;

      .van-radio-group {
        height: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .van-radio--horizontal {
          margin-right: 0 !important;
        }
      }
    }

    .refundNumber {
      padding: 20px 30px 0;
    }

    .problem1 {
      box-sizing: border-box;
      padding: 5px 5.333vw;
      /**
       * @name: Hou
       * @msg: 5px 5.333vw;
       * @Date: 2020-12-15 11:38:08
       */
      text-align: left;

      .title {
        margin: 2.133vw 0 0 0;
        font-size: 5vw;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: left;
        color: #000000;
      }
    }

    .problem {
      box-sizing: border-box;
      padding: 5px 40px;
      padding-bottom: 30px;

      .title {
        margin: 31px 0;
        font-size: 5vw;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: left;
        color: #000000;
      }

      /deep/ .van-cell {
        height: 270px;
        // background-color: #F3EBEB;
        border-radius: 15px;

        background: #f3ebeb
          url("https://cdn.92jiangbei.com/bc-double-twelve/feedback.png")
          no-repeat right 19px bottom 26px;
        background-size: 21.067vw;

        .van-field__body {
          height: 250px;

          .van-field__control {
            height: 250px !important;
            color: #787878 !important;
          }
        }

        .van-field__word-limit {
          margin-top: -14px !important;
        }
      }
    }

    .up {
      width: 100%;
      height: 180px;
      box-sizing: border-box;
      padding: 0 40px;

      .van-uploader {
        width: 100%;
        float: left;
      }
    }
    .tips {
      width: 100%;
      height: 40px;
      box-sizing: border-box;
      margin-top: 10px;
      padding: 0 40px;
      text-align: left;
      font-size: 26px;
      color: #494949;
      line-height: 40px;
    }
  }

  .tel {
    width: 100%;
    height: 40px;
    margin-top: 27px;
    margin-bottom: 18.667vw;
    line-height: 40px;
    font-size: 26px;
    font-weight: 400;
    color: #494949;
    text-align: center;
    a {
      font-size: 28px;
      color: rgba(15, 121, 240, 1);
      text-decoration: underline;
    }
  }

  .footer {
    margin-bottom: 55px;
    height: 150px;
    background-color: #f4f5f7;
    z-index: 999;
    .footer-c {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 690px;
      height: 90px;
      margin: 0 auto;
      background: #ececec;
      border-radius: 45px;
      overflow: hidden;

      .cancel,
      .submit {
        width: 210px;
        height: 100%;
        text-align: center;
        font-size: 30px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        color: #cacaca;
        line-height: 90px;
      }

      .submit {
        width: 480px;
        font-size: 30px;
        color: #ffffff;
        background: linear-gradient(84deg, #d1203c 4%, #b0071e 69%);
      }
    }
  }
}

.courierNum {
  margin-top: 3.6vw;
  margin-bottom: 57px;
  .title {
    height: 55px;
    line-height: 55px;
  }
  padding: 0 40px;
  .courierNum_body {
    width: 420px;
    border: 1px solid #979797;
    border-radius: 15px;

    font-size: 30px;
    color: #000000;
    input {
      width: 90%;
      border: 0 none;
      line-height: 55px;
      border-radius: 15px;
    }
  }
}
</style>
